package com.dys.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Author: 疾风
 * @ClassName: LoginCheckServlet
 * @Description: 检查是否登录过
 * @CreateDate: 2024/09/25
 * @Version: v1.0.0
 */
@WebServlet(urlPatterns = "/loginCheckServlet.do")
public class LoginCheckServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        // 判断是否登录
        Object user = session.getAttribute("user");
        // 获得对应的监听器
        Object listener = session.getAttribute("listener");
        String message = "";
        if (user !=null) {
            message="您已经登录过";
        }else {
            message="您还未登录";
        }
        resp.setContentType("text/html;charset=UTF-8");
        resp.getWriter().write(message);
    }
}
